<?php
$cs = Yii::app()->getClientScript();
$cs->registerCSSFile(Yii::app()->request->baseUrl . '/css/mobile/booking_find.css');
?>
<div data-role='page' id='demo-page'>
    <div data-role="header">
        <h1>添加预订</h1>
    </div>
    <div data-role='content' id='mainContent' style="padding: 5px;">
        <?php
        $screen = Blyn::app()->getUIManager()->getCurrentScreen();
        $wxControl = $screen->getChildControl('BUIWXControl_1');
        $wxControl->renderView('booking_home', array());
        $bookingItem = new BWInputValue($bookingId);
        $bookingList = new BTreeList($bookingItem);
        ?>
        <?php
        $form = $this->beginWidget('CActiveForm', array(
            "id" => "post-form-2",
            'enableAjaxValidation' => FALSE,
            'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));
        ?>
        <?php
        $url = $control->getAjaxLinkUrl('addToBookingCart_1', 'addToBookingCart_1', array(
            'bookingId' => $bookingId));
        $updateId = $control->getAjaxContainerId();
        ?>
        <script type="text/javascript">
            // this script for collecting the form data and pass to the controller action and doing the on success validations
            function addToBookingCart() {

                var formData = new FormData($("#message-form")[0]);
                //var formElement = document.getElementById("message-form");
                //var formData = new FormData(formElement);

                $.ajax({
                    url: '<?php echo $url; ?>',
                    type: 'POST',
                    data: formData,
                    datatype: 'json',
                    // async: false,
                    beforeSend: function() {
                        $("#ajax-loaderdiv").show();
                    },
                    success: function(html) {
                        // on success do some validation or refresh the content div to display the uploaded images 
                        jQuery("#<?php echo $updateId; ?>").html(html);
                        //alert(data);
                    },
                    complete: function() {
                        $("#ajax-loaderdiv").hide();
                    },
                    error: function() {
                        alert("There may a error on uploading. Try again later");
                    },
                    cache: false,
                    contentType: false,
                    processData: false
                });

                return false;
            }
        </script>
        <div class="modal-header">
            <!--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>-->
                <?php
//        echo $wxControl->getLink(array('name' => '搜索列表', 'id' => 'showBookingList_1'), array(
//            'findText' => $findText));
                ?><!--\
                预订场地-->
        </div>
        <table data-role="table" id="table-custom-2" data-mode="columntoggle" class="ui-body-d ui-shadow table-stripe ui-responsive" data-column-btn-theme="b" data-column-btn-text="显示列" data-column-popup-theme="a">
            <thead>
                <tr>
                    <th data-priority="1">预订项属性</th>
                    <th data-priority="1">预订项内容</th>
                </tr>
            </thead>
            <tbody>
                <?php if ($bookingList instanceof BTreeList) { ?>
                    <tr>
                        <td>
                            <code>场地商名称</code>
                        </td>
                        <td>
                            <?php echo $bookingList->getItem('venderName')->value; ?>
                        </td>
                    </tr>
                    <tr><td> <code>场地名称</code> </td>
                        <td>
                            <?php echo $bookingList->getItem('courtDisplayName')->value; ?>
                        </td>
                    </tr> 
                    <tr><td> <code>所属地区</code> </td>
                        <td>
                            <?php
                            $addressId = $bookingList->getItem('region')->value;
                            $address = new BWAddress($addressId);
                            echo $address->fullName;
                            ?>
                        </td>
                    </tr> 
                    <tr><td> <code>详细地址</code> </td>
                        <td>
                            <?php echo $bookingList->getItem('courtAddress')->value; ?>
                        </td>
                    </tr> 
                    <tr><td> <code>场地价格</code> </td>
                        <td>
                            <?php echo $bookingList->getItem('price')->value; ?>
                        </td>
                    </tr> 
                    <tr><td> <code>场地图片</code> </td>
                        <td>
                            <?php
                            $str = $bookingList->getItem('courtName')->value;
                            $str = trim($str);
                            if (!empty($str)) {
                                $result = '';
                                for ($i = 0; $i < strlen($str); $i++) {
                                    if (is_numeric($str[$i])) {
                                        $result.=$str[$i];
                                    }
                                }
                            }
                            $bookdetail = new BWMessage($result);
                            $courtImageMedia = $bookdetail->getMediaManager()->getMedia('image');
                            if ($courtImageMedia instanceof BWMedia) {
                                $courtImage = $bookdetail->getMediaManager()->getMedia('image')->getContent();
                                ?>
                                <img src="<?php echo Yii::app()->request->baseUrl . $courtImage; ?>" width="40" height="35"/>
                            <?php } else { ?>
                                <h4>No Picture!</h4>
                            <?php } ?>
                        </td>
                    </tr>
                    <tr>
                        <td> <code>场地简介</code>  </td>                    
                        <td>
                            <?php echo $bookingList->getItem('courtDescription')->value; ?>
                        </td>

                    </tr>
                    <tr><td> <code>场地开始时间:(0-23)</code> </td>
                        <td>
                            <?php
                            $startTime = $bookingList->getItem('startTime')->value;
                            echo date('Y-m-d G:i:s', $startTime);
                            ?>
                        </td>
                    </tr> 
                    <tr><td> <code>场地结束时间:(0-23)</code> </td>
                        <td>
                            <?php
                            $endTime = $bookingList->getItem('endTime')->value;
                            echo date('Y-m-d G:i:s', $endTime);
                            ?>
                        </td>
                    </tr> 
                    <tr><td> <code>预订开始时间:(0-23)</code> </td>
                        <td>
                            <?php
                            $bookingStartTime = $bookingList->getItem('bookingStartTime')->value;
                            echo date('Y-m-d G:i:s', $bookingStartTime);
                            ?> 
                        </td>
                    </tr> 
                    <tr><td> <code>预订结束时间:(0-23)</code> </td>
                        <td>
                            <?php
                            $bookingEndTime = $bookingList->getItem('bookingEndTime')->value;
                            echo date('Y-m-d G:i:s', $bookingEndTime);
                            ?>
                        </td>
                    </tr>
                    <tr><td> <code>预订状态:</code> </td>
                        <td>
                            <?php
                            $bookingStatus = $bookingList->getItem('bookingStatus')->value;
                            echo  Yii::t('BWeSport', $bookingStatus);
                            ?>
                        </td>
                    </tr>
                <?php } ?>

            </tbody>
        </table>   

        <?php $this->endWidget(); ?>
        <div class="modal-footer">
            <fieldset class="ui-grid-a">
                <div class="ui-block-a"><?php echo $wxControl->getLink(array('name' => '加入预订清单', 'id' => 'addToBookingCart_1'), array('bookingId' => $bookingId, 'findText' => $findText, 'findContext' => $findContext, 'htmlOptions' => array('class' => 'ui-btn ui-mini ui-corner-all ui-btn-active'))); ?></div>
                <div class="ui-block-b"><?php echo $wxControl->getLink(array('name' => '返回列表', 'id' => 'showBookingList_1'), array('findText' => $findText, 'findContext' => $findContext, 'htmlOptions' => array('class' => 'ui-btn ui-mini ui-corner-all'))); ?></div>
            </fieldset>
        </div>
        <br/>
        <br/>
    </div>
    <div data-role="footer" data-position="fixed">
        <div data-role="navbar">
            <ul>
                <li><a href="#" id="find" data-icon="search" class="ui-btn-active">分类查询</a></li>
                <li><a href="#" id="mybooking" data-icon="shop">我的预订</a></li>
                <li><a href="#" data-icon="gear">其他</a></li>
            </ul>
        </div><!-- /navbar -->
    </div><!-- /footer -->